package main

import (
	"fmt"
	"html/template"
	"net/http"
)

func sayhello(w http.ResponseWriter, r *http.Request) {
	//解析指定文件生成模板对象
	tmpl, err := template.ParseFiles("D:\\go1.21.3.windows-amd64\\go_clone\\Go-基本知识\\Go常用的库\\_template\\index.html")
	if err != nil {
		fmt.Println("create template failed, err:", err)
		return
	}
	//利用给定的数据渲染模板，并将结果写入w
	tmpl.Execute(w, "jcut.com")
}

func main() {
	http.HandleFunc("/", sayhello)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		fmt.Println("HTTP server failed,err:", err)
		return
	}
}
